package com.sky.cqculture.service.impl;

import com.sky.cqculture.Mapper.CategoryMapper;
import com.sky.cqculture.pojo.Category;
import com.sky.cqculture.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {
    
    @Autowired
    private CategoryMapper categoryMapper;
    
    @Override
    public List<Category> findAllCategories() {
        return categoryMapper.findAll();
    }
    
    @Override
    public Category findCategoryById(Integer id) {
        return categoryMapper.findById(id);
    }
    
    @Override
    public void addCategory(Category category) {
        category.setCreateTime(new Date());
        category.setUpdateTime(new Date());
        categoryMapper.insert(category);
    }
    
    @Override
    public void updateCategory(Category category) {
        category.setUpdateTime(new Date());
        categoryMapper.update(category);
    }
    
    @Override
    public void deleteCategoryById(Integer id) {
        categoryMapper.deleteById(id);
    }
}